<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<title>泸州化工食堂后台管理系统</title>
		<link rel="stylesheet" href="../layui/css/layui.css">
		<link rel="stylesheet" href="../css/index.css">
	</head>
	<body class="layui-layout-body">
		<form style="margin-left: 10%;margin-top: 2%;" class="layui-form layui-form-pane" action="">
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">菜品名称</label>
					<div class="layui-input-inline">
						<input type="tel" name="name" lay-verify="required" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">菜品类型</label>
					<div class="layui-input-inline">
						<select lay-verify="required" name="typeId" id="typeSelect" >
							<option value=""></option>
						  </select>
					</div>
				</div>
				<div class="layui-form-item layui-form-text">
					<label class="layui-form-label">菜品描述</label>
					<div class="layui-input-block">
						<textarea lay-verify="required" placeholder="请输入内容" class="layui-textarea" name="desc"></textarea>
					</div>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn" lay-submit="" lay-filter="addMenu">立即提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>
		<script src="../layui/layui.js"></script>
		<script src="../js/index.js"></script>

		<script>
			layui.use(['form','jquery','table'], function() {
				var form = layui.form,
				$=layui.jquery,
				table=layui.table
				
				$(function(){
					//加载菜品类型
					$.ajax({
						type:'get',
						url:'//rimi.liangdian.online/type',
						success:function(res){
								for (var i=0;i<res.length;i++) {
									var type=res[i];
									$("#typeSelect").append('<option value="'+type.id+'">'+type.name+'</option>');
								}
								form.render('select'); 
						}
					});
				})

				//监听提交
				form.on('submit(addMenu)', function(data) {
					$.ajax({
						type:'post',
						url:'//rimi.liangdian.online/manager/menu',
						data:data.field,
						success:function(res){
							if(res.code==0){
								var index = parent.layer.getFrameIndex(window.name);
								layer.msg("添加菜品成功",{icon:1},function(){
									 parent.location.reload();
								});
								return;
							}
							layer.msg(res.msg);
						}
					});
					return false;
				});
			})
		</script>
	</body>
</html>
